home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / cbibcode.arc / CABS.C < prev    next >
Encoding:
C/C++ Source or Header  |  1991-08-05  |  560 b   |  21 lines

  1. /* cabs.c function, from  p.200 of Turbo C Bible */
  2. struct complex
  3. {
  4.     double x;               /* Real part of complex number  */
  5.     double y;               /* Imaginery part of complex number */
  6. };
  7. #include <stdio.h>
  8. #include <math.h>
  9. #include <stdlib.h>                    /* errno is defined here */
  10. main()
  11. {
  12.     struct complex z;
  13.     double result;
  14.     printf("enter complex number in form \"(real, imaginery)\":");
  15.     scanf(" (%le , %le )", &z.x, &z.y);
  16.     result = cabs(z);
  17.     if(errno != ERANGE)
  18.     {
  19.         printf("magnitude of (%f, %f) = %f\n",z.x, z.y, result);
  20.     }
  21. }